<?php require_once('Connections/locamedicadmin.php'); ?>

<?php include('userValidation.php'); ?>

<?php require_once('functions.php'); ?>


<?php

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
  $errors = array();
  
  $name = trim($_POST['name_FR']);
  
  if (strlen($name) == 0) {
  	array_push($errors, "Nom ne peut pas être vide");
  } else if (strlen($name) > 40) {
  	array_push($errors, "Nom ne peut pas être plus long que 40 caractères");
  }
  
  $manu_num = trim($_POST['manu_num']);
  
  if (strlen($manu_num) == 0) {
  	array_push($errors, "Nombre manufacture ne peut pas être vide");
  } else if (strlen($manu_num) > 40) {
  	array_push($errors, "Nombre manufacture ne peut pas être plus long que 40 caractères");
  }
  
  if (sizeof($errors) == 0) { 
  
	  $insertSQL = sprintf("INSERT INTO csre_manufacture (name_FR, name_US, manu_num) VALUES (%s, %s, %s)",
						   GetSQLValueString($name, "text"),
						   GetSQLValueString($_POST['name_FR'], "text"),
						   GetSQLValueString($_POST['manu_num'], "text"));
	
	  mysql_select_db($database_locamedicadmin, $locamedicadmin);
	  $Result1 = mysql_query($insertSQL, $locamedicadmin) or die(mysql_error());
	  
	  header("Location: manufacture_list.php"); 
  }
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Locamedic CSRE Admin</title>
<link href="locamedicadmin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="page">

	<?php include('sidebar.php'); ?>
	
	<!-- end sidebar -->
	<div id="content">
		<div align="center"><img src="images/page_image_5.jpg" alt="" /></div>
	  <div class="boxed">
			<h1 class="title2">Ajouter un manufacture</h1>
			
			<?php include('errors.php'); ?>
	  
            <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
              <table>
                <tr valign="baseline">
                  <td nowrap >Name:</td>
                  <td><input type="text" name="name_FR" value="<?php echo getValor('name_FR');?>" maxlength="40" size="32"></td>
                </tr>
				<tr valign="baseline">
                  <td nowrap ># Manufacture:</td>
                  <td><input type="text" name="manu_num" value="<?php echo getValor('manu_num');?>" maxlength="40" size="32"></td>
                </tr>
              </table>
			  <div class="botonera">
			  	<input type="submit" value="Save">
				<input type="button" onclick="window.location='manufacture_list.php'" value="Cancel" />
			  </div>
              <input type="hidden" name="MM_insert" value="form1">
            </form>
            <p>&nbsp;</p>
	  </div>
  </div>
	<!-- end content -->
	<div style="clear: both;">&nbsp;</div>
</div>
<!-- end page -->

<?php include('footer.php'); ?>

</body>
</html>